package com.moyu.common.core.utils;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * 生成10位随机数的账号(首位不为0)
 *
 * @Author 赵彦博
 * @Date 2024/12/23 10:07
 */
@Data
@Component
public class BuildAccount {

    public String userAccount;

    public String init() {
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        while (stringBuilder.length() < 10) {//生成随机10位数账号
            int c = random.nextInt(10);
            if (stringBuilder.length() == 0) {
                if (c != 0) {
                    stringBuilder.append(c);
                }
            } else {
                stringBuilder.append(c);
            }
        }
        return userAccount = stringBuilder.toString();
    }

}
